package com.yykj.user.center.server.controller.patient;

import com.yykj.common.util.LocalStringUtil;
import com.yykj.common.vo.ResultVO;
import com.yykj.message.center.client.feign.MessageFeignClient;
import com.yykj.user.center.server.dto.UserLoginInfo;
import com.yykj.user.center.server.form.GetCodeForm;
import com.yykj.user.center.server.form.RegisterForm;
import com.yykj.user.center.server.form.UserLoginForm;
import com.yykj.user.center.server.service.patient.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chenl
 * @version 1.0
 * @date 2021/10/20 21:38
 */

@Api(tags = "患者端登录相关接口")
@RestController
@RequestMapping("/api/patientLogin")
@SuppressWarnings("unchecked")
@Slf4j
public class LoginController {
    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    @ApiOperation("帐号密码登录")
    public ResultVO<UserLoginInfo> login(@RequestBody UserLoginForm form){
        return ResultVO.success(loginService.login(form));
    }

    @PostMapping("/codeLogin")
    @ApiOperation("验证码登录")
    public ResultVO codeLogin(@RequestBody UserLoginForm form){
        return ResultVO.success(loginService.codeLogin(form));
    }

    @GetMapping("/isRegister")
    @ApiOperation("校验该患者是否已经注册过帐号")
    public ResultVO isRegister(@RequestBody UserLoginForm form){
        return ResultVO.success(loginService.isRegister(form));
    }

    @ApiImplicitParam(name = "mobile",value = "手机号",required = true)
    @GetMapping("/sendCode")
    @ApiOperation("获取验证码")
    public ResultVO sendCode(@RequestParam(name = "mobile" ,required = true)String mobile){
        return ResultVO.success(loginService.getCode(mobile));
    }

    @PostMapping("/register")
    @ApiOperation("注册")
    public ResultVO register(@RequestBody RegisterForm registerForm){
        return ResultVO.success(loginService.register(registerForm));
    }


}
